<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
  <link rel="stylesheet" href="/css/public.css" media="all">
  <style>
    body {
      background-color: #ffffff;
    }
  </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="example">
  <div class="layui-form-item" style="display: none" >
    <label class="layui-form-label">供应商id</label>
    <div class="layui-input-block">
      <input type="text" name="id" placeholder="请输入供应商id" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商编码</label>
    <div class="layui-input-block">
      <input type="text" name="proCode"   placeholder="请输入供应商编码" value=" " class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商名称</label>
    <div class="layui-input-block">
      <input type="text" name="proName"   placeholder="请输入供应商名称" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商描述</label>
    <div class="layui-input-block">
      <input type="text" name="proDesc"   placeholder="请输入供应商描述" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商联系人</label>
    <div class="layui-input-block">
      <input type="text" name="proContact"   placeholder="请输入供应商联系人" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商电话</label>
    <div class="layui-input-block">
      <input type="phone" name="proPhone" placeholder="请输入供应商电话" value="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">供应商地址</label>
    <div class="layui-input-block">
      <input type="text" name="proAddress" placeholder="请输入供应商地址" value="" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item" style="float: right">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn" >确认保存</button>
    </div>
  </div>
</div>
</body>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
  layui.use(['form'], function () {
    var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
    //获取id
    const urlParams = new URLSearchParams(window.location.search);
    const id = urlParams.get('id');
    if (id!=null){
      $.getJSON("/pro/selectById",{id:id}, function (result) {
        if (result.code==200) {
          //表单初始赋值
          form.val('example', result.data);
        }
      });
    }
    //监听提交
    form.on('submit(saveBtn)', function (data) {
      $.post("/pro/editProOrAddPro",data.field,function (result){
        parent.layer.alert(result.msg,function (){
          if (result.code==200){
            //关闭所有弹出的窗口
            parent.layer.closeAll();
            parent.tab.reload();
          }
        })

      })
      return false;
    });

  });
</script>
</body>
</html>